import 'package:easy_refresh/easy_refresh.dart';
import 'package:flutter/material.dart';
import 'package:jd_flutter/base/widget/refresh/jd_indicator.dart';

class JDRefreshHeader extends Header {
  const JDRefreshHeader({
    double triggerOffset = 70,
    bool clamping = false,
    IndicatorPosition position = IndicatorPosition.behind,
    Duration processedDuration = const Duration(seconds: 1),
    SpringDescription? spring,
    SpringBuilder? readySpringBuilder,
    bool springRebound = true,
    FrictionFactor? frictionFactor,
    bool safeArea = true,
    double? infiniteOffset,
    bool? hitOver,
    bool? infiniteHitOver,
    bool hapticFeedback = false,
    bool triggerWhenReach = false,
    bool triggerWhenRelease = false,
    double maxOverOffset = double.infinity,
  }) : super(
          triggerOffset: triggerOffset,
          clamping: clamping,
          processedDuration: processedDuration,
          spring: spring,
          readySpringBuilder: readySpringBuilder,
          springRebound: springRebound,
          frictionFactor: frictionFactor,
          safeArea: safeArea,
          infiniteOffset: infiniteOffset,
          hitOver: hitOver,
          infiniteHitOver: infiniteHitOver,
          position: position,
          hapticFeedback: hapticFeedback,
          triggerWhenReach: triggerWhenReach,
          triggerWhenRelease: triggerWhenRelease,
          maxOverOffset: maxOverOffset,
        );

  @override
  Widget build(BuildContext context, IndicatorState state) {
    return JDIndicator(
      state: state,
      backgroundColor: null,
      mainAxisAlignment: MainAxisAlignment.center,
      dragText: '下拉刷新',
      armedText: '释放立即刷新',
      readyText: '正在刷新...',
      processingText: '正在刷新...',
      processedText: '刷新完成',
      noMoreText: '没有更多了~',
      failedText: '刷新失败',
      showText: false,
      messageText: '上次更新时间 %T',
      showMessage: false,
      textDimension: null,
      showIcon: true,
      iconDimension: 24,
      spacing: 16,
      reverse: state.reverse,
      succeededIcon: null,
      failedIcon: null,
      noMoreIcon: null,
      pullIconBuilder: null,
      textStyle: null,
      textBuilder: null,
      messageStyle: null,
      messageBuilder: null,
      clipBehavior: Clip.hardEdge,
      iconTheme: null,
      progressIndicatorSize: null,
      progressIndicatorStrokeWidth: null,
    );
  }
}

class JDWhiteRefreshHeader extends Header {
  const JDWhiteRefreshHeader({
    double triggerOffset = 70,
    bool clamping = false,
    IndicatorPosition position = IndicatorPosition.behind,
    Duration processedDuration = const Duration(seconds: 1),
    SpringDescription? spring,
    SpringBuilder? readySpringBuilder,
    bool springRebound = true,
    FrictionFactor? frictionFactor,
    bool safeArea = true,
    double? infiniteOffset,
    bool? hitOver,
    bool? infiniteHitOver,
    bool hapticFeedback = false,
    bool triggerWhenReach = false,
    bool triggerWhenRelease = false,
    double maxOverOffset = double.infinity,
  }) : super(
          triggerOffset: triggerOffset,
          clamping: clamping,
          processedDuration: processedDuration,
          spring: spring,
          readySpringBuilder: readySpringBuilder,
          springRebound: springRebound,
          frictionFactor: frictionFactor,
          safeArea: safeArea,
          infiniteOffset: infiniteOffset,
          hitOver: hitOver,
          infiniteHitOver: infiniteHitOver,
          position: position,
          hapticFeedback: hapticFeedback,
          triggerWhenReach: triggerWhenReach,
          triggerWhenRelease: triggerWhenRelease,
          maxOverOffset: maxOverOffset,
        );

  @override
  Widget build(BuildContext context, IndicatorState state) {
    return JDIndicator(
      state: state,
      backgroundColor: null,
      iconColor: Colors.white,
      mainAxisAlignment: MainAxisAlignment.center,
      dragText: '下拉刷新',
      armedText: '释放立即刷新',
      readyText: '正在刷新...',
      processingText: '正在刷新...',
      processedText: '刷新完成',
      noMoreText: '没有更多了~',
      failedText: '刷新失败',
      showText: false,
      messageText: '上次更新时间 %T',
      showMessage: false,
      textDimension: null,
      showIcon: true,
      iconDimension: 24,
      spacing: 16,
      reverse: state.reverse,
      succeededIcon: null,
      failedIcon: null,
      noMoreIcon: null,
      pullIconBuilder: null,
      textStyle: null,
      textBuilder: null,
      messageStyle: null,
      messageBuilder: null,
      clipBehavior: Clip.hardEdge,
      iconTheme: null,
      progressIndicatorSize: null,
      progressIndicatorStrokeWidth: null,
    );
  }
}
